<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 
class ProtModel extends BaseModel
{

    var $table  = 'content';	

    var $_page_rows = 10;	
	

    function show($order='',$v='',$word='',$cat = '')
    {  
	     empty($order)?$order = 'A.add_time desc':'';
		 $conditions = "A.lang_type='".trim($GLOBALS['Lang']->_lang_tp)."' ";
		 empty($cat)?$conditions .= " and A.user_id >0 and A.table_id=2":$conditions .= " and (A.cat_id =$cat or A.parent_id =$cat) and  A.user_id >0 and A.table_id=2";
		 foreach($word as $key => $value)
		 {
			 if($key == 'index')//判断是否在首页显示
			 {
			 	$conditions .= " and A.keywords like '%{$value}%' ";
			 }
		     else if($value)
		     {
		      $conditions .= " and C.title like '%{$value}%' ";
	  
		     }
		 }	
		  
/*	
  "SELECT A.*,C.* FROM content A LEFT JOIN content_1 C ON A.id=C.con_id WHERE A.id='$aid' ORDER BY R.rid ASC LIMIT 1"
	  
	  'table'=> $this->$table.'A LEFT JOIN '.$this->_prefix.'content_1  C ON A.id=C.con_id '
	  'fields'=> ' A.*,C.* ';
	  */
	  
	     $table = $this->table.' A LEFT JOIN '.$this->_prefix.'content_2'.' C ON A.id=C.con_id ';
	  
	      //��ҳʱ��һ�����ȵ���page�����ٵ���S_Sql_Exe����
		 $info['page'] = $this->Page(array('table'=>"{$table}",'conditions' =>"{$conditions}",'url' => '?app=prot&act=index&cat='.$cat));		
		 
		 $info['data'] = $this->S_Sql_Exe(array('table'=>"{$table}",'fields'=> ' A.*,C.* ','conditions' =>"{$conditions}",'order' =>"{$order}",'limit' =>$info['page']['sql_limit']));
    
		 return $info;
   
    }
	

    function inindex()
    {    
	    
         $order = 'A.add_time desc';
		 
	     $table = $this->table.' A LEFT JOIN '.$this->_prefix.'content_2'.' C ON A.id=C.con_id ';
	  
		 $info = $this->S_Sql_Exe(array('table'=>"{$table}",'fields'=> ' A.*,C.* ','conditions' =>"A.is_show=1 and A.is_index=1 and A.table_id=2 and A.user_id >0  and A.lang_type='".trim($GLOBALS['Lang']->_lang_tp)."' ",'order' =>"{$order}",'limit' =>9));
    
		 return $info;
        
    }



    /* ͨ��idȡ��һ����� */
    function oneshow($id ='')
    {    
	    

	     $table = $this->table.' A LEFT JOIN '.$this->_prefix.'content_2'.' C ON A.id=C.con_id ';
	  
		 $info = $this->S_Sql_Exe(array('table'=>"{$table}",'fields'=> ' A.*,C.* ','conditions' =>"A.id='{$id}' and A.user_id >0  and A.lang_type='".trim($GLOBALS['Lang']->_lang_tp)."' ",'return' =>'one'));
    
		 return $info;
        
    }
    function vistnumadd($id='')
    {    
		 
		$sql='update '.$this->table.' set visit_num = visit_num + 1 where id = '.intval($id);
		$query = $this->db->query($sql);     
		return true;
    }


}




?>